package fileshare.fileprocessing;

import java.io.File;
	import java.io.FileInputStream;
	import java.io.FileNotFoundException;
	import java.io.FileOutputStream;
	import java.io.IOException;
	import java.util.ArrayList;
	import java.util.Iterator;
import java.io.*;

import fileshare.network.peerProcess;
public class ParseTracker
{
	
	
		private static int FileSize;
		private static int PieceSize;
		private static int NOPeer;
		private static int UnchInter;
		private static int Optinter;
		private static String FileName;

		/*private File f = null;
		public static void main(String args[])
		{
			
			int k=582559388;
			System.out.println("k"+k);
			getTracker();
		}*/
		public static void getTracker()
		{
			parsefile();
			peerProcess.realfilename=FileName;
			peerProcess.filesize=FileSize;
			peerProcess.piecesize=PieceSize;
			peerProcess.NumberOfPreferred=NOPeer;
			peerProcess.OptUnchokeinterval=Optinter;
			peerProcess.Unchokeinterval=UnchInter;
			int index=FileName.lastIndexOf(".");
			//the extention
			peerProcess.ext=FileName.substring(index);
			
			
		}
		public static void parsefile()
		{
			try
			{
			BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("CEN5501C//Common.cfg")));
			/*String NumberOfPeer;
			String UnchokingInterval;
			String OptimisticUnchokingInterval;
			String FileName;
			String FileSize;
			String PieceSize;*/

			for(int i=0;i<6;i++)
			{
				String result=in.readLine();
				switch(i){
				case 0:
					{
						NOPeer=getdata(result);
					}break;
				
				case 1: {UnchInter=getdata(result);}break;
				case 2: Optinter=getdata(result);break;
				case 3: FileName=getfilename(result);break;
				case 4: FileSize=getdata(result);break;
				case 5: PieceSize=getdata(result);break;
				}
					
			}
		

			}catch(IOException e){e.printStackTrace();log.getExceptionTrace(e);}
			
		}
		private static int getdata(String source)
		{
			int index=source.lastIndexOf(" ");
			String data=source.substring(index+1);
			int k=Integer.parseInt(data);
			System.out.println(k);
			return k;
		}
		private static String getfilename(String source)
		{
			int index=source.lastIndexOf(" ");
			String data=source.substring(index+1);
			return data;
		}
		
	}
	



